package com.huiyi.shopping_order.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.huiyi.common.annotation.Log;
import com.huiyi.common.core.controller.BaseController;
import com.huiyi.common.core.domain.AjaxResult;
import com.huiyi.common.enums.BusinessType;
import com.huiyi.shopping_order.domain.ShoppingOrder;
import com.huiyi.shopping_order.service.IShoppingOrderService;
import com.huiyi.common.utils.poi.ExcelUtil;
import com.huiyi.common.core.page.TableDataInfo;

/**
 * 购物订单Controller
 * 
 * @author ruoyi
 * @date 2024-11-28
 */
@RestController
@RequestMapping("/shopping_order/shopping_order")
public class ShoppingOrderController extends BaseController
{
    @Autowired
    private IShoppingOrderService shoppingOrderService;

    /**
     * 查询购物订单列表
     */
    @PreAuthorize("@ss.hasPermi('shopping_order:shopping_order:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShoppingOrder shoppingOrder)
    {
        startPage();
        List<ShoppingOrder> list = shoppingOrderService.selectShoppingOrderList(shoppingOrder);
        return getDataTable(list);
    }

    /**
     * 导出购物订单列表
     */
    @PreAuthorize("@ss.hasPermi('shopping_order:shopping_order:export')")
    @Log(title = "购物订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShoppingOrder shoppingOrder)
    {
        List<ShoppingOrder> list = shoppingOrderService.selectShoppingOrderList(shoppingOrder);
        ExcelUtil<ShoppingOrder> util = new ExcelUtil<ShoppingOrder>(ShoppingOrder.class);
        util.exportExcel(response, list, "购物订单数据");
    }

    /**
     * 获取购物订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('shopping_order:shopping_order:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(shoppingOrderService.selectShoppingOrderById(id));
    }

    /**
     * 新增购物订单
     */
    @PreAuthorize("@ss.hasPermi('shopping_order:shopping_order:add')")
    @Log(title = "购物订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShoppingOrder shoppingOrder)
    {
        return toAjax(shoppingOrderService.insertShoppingOrder(shoppingOrder));
    }

    /**
     * 修改购物订单
     */
    @PreAuthorize("@ss.hasPermi('shopping_order:shopping_order:edit')")
    @Log(title = "购物订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShoppingOrder shoppingOrder)
    {
        return toAjax(shoppingOrderService.updateShoppingOrder(shoppingOrder));
    }

    /**
     * 删除购物订单
     */
    @PreAuthorize("@ss.hasPermi('shopping_order:shopping_order:remove')")
    @Log(title = "购物订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(shoppingOrderService.deleteShoppingOrderByIds(ids));
    }
}
